<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>lightweight_test</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="prev" href="is_same.html" title="is_same">
<link rel="next" href="no_exceptions_support.html" title="no_exceptions_support">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="is_same.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="no_exceptions_support.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="core.lightweight_test"></a><a class="link" href="lightweight_test.html" title="lightweight_test">lightweight_test</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te">Header
      &lt;boost/core/lightweight_test.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_t0">Header
      &lt;boost/core/lightweight_test_trait.hpp&gt;</a></span></dt>
</dl></div>
<div class="simplesect">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm7782"></a>Authors</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          Peter Dimov
        </li>
<li class="listitem">
          Beman Dawes
        </li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te" title="Header &lt;boost/core/lightweight_test.hpp&gt;">Header
      &lt;boost/core/lightweight_test.hpp&gt;</a>
</h3></div></div></div>
<p>
        The header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">lightweight_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        is a lightweight test framework. It's useful for writing Boost regression
        tests for components that are dependencies of Boost.Test.
      </p>
<p>
        When using <code class="computeroutput"><span class="identifier">lightweight_test</span><span class="special">.</span><span class="identifier">hpp</span></code>,
        <span class="bold"><strong>do not forget</strong></span> to <code class="computeroutput"><span class="keyword">return</span>
        <span class="identifier">boost</span><span class="special">::</span><span class="identifier">report_errors</span><span class="special">()</span></code>
        from <code class="computeroutput"><span class="identifier">main</span></code>.
      </p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.synopsis"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.synopsis" title="Synopsis">Synopsis</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">expression</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_NOT</span><span class="special">(</span><span class="identifier">expression</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_ERROR</span><span class="special">(</span><span class="identifier">message</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_EQ</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_NE</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_LT</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_LE</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_GT</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_GE</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_CSTR_EQ</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_CSTR_NE</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_WITH</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">,</span> <span class="identifier">pred</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_ALL_EQ</span><span class="special">(</span><span class="identifier">begin1</span><span class="special">,</span> <span class="identifier">end1</span><span class="special">,</span> <span class="identifier">begin2</span><span class="special">,</span> <span class="identifier">end2</span><span class="special">)</span> <span class="comment">/* unspecified */</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_ALL_WITH</span><span class="special">(</span><span class="identifier">begin1</span><span class="special">,</span> <span class="identifier">end1</span><span class="special">,</span> <span class="identifier">begin2</span><span class="special">,</span> <span class="identifier">end2</span><span class="special">,</span> <span class="identifier">predicate</span><span class="special">)</span> <span class="comment">/* unspecified */</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_THROWS</span><span class="special">(</span><span class="identifier">expr</span><span class="special">,</span> <span class="identifier">excep</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_NO_THROW</span><span class="special">(</span><span class="identifier">expr</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>

<span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
    <span class="keyword">int</span> <span class="identifier">report_errors</span><span class="special">();</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test" title="BOOST_TEST">BOOST_TEST</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">expression</span><span class="special">)</span>
</pre>
<p>
          If expression is false increases the error count and outputs a message
          containing <code class="computeroutput"><span class="identifier">expression</span></code>.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_not"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_not" title="BOOST_TEST_NOT">BOOST_TEST_NOT</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_NOT</span><span class="special">(</span><span class="identifier">expression</span><span class="special">)</span>
</pre>
<p>
          If expression is true increases the error count and outputs a message containing
          <code class="computeroutput"><span class="special">!(</span><span class="identifier">expression</span><span class="special">)</span></code>.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_error"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_error" title="BOOST_ERROR">BOOST_ERROR</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_ERROR</span><span class="special">(</span><span class="identifier">message</span><span class="special">)</span>
</pre>
<p>
          Increases error count and outputs a message containing <code class="computeroutput"><span class="identifier">message</span></code>.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_eq"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_eq" title="BOOST_TEST_EQ">BOOST_TEST_EQ</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_EQ</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">expr1</span> <span class="special">==</span>
          <span class="identifier">expr2</span></code> is not true increases the
          error count and outputs a message containing both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_ne"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_ne" title="BOOST_TEST_NE">BOOST_TEST_NE</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_NE</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">expr1</span> <span class="special">!=</span>
          <span class="identifier">expr2</span></code> is not true increases the
          error count and outputs a message containing both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_lt"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_lt" title="BOOST_TEST_LT">BOOST_TEST_LT</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_LT</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">expr1</span> <span class="special">&lt;</span>
          <span class="identifier">expr2</span></code> is not true increases the
          error count and outputs a message containing both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_le"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_le" title="BOOST_TEST_LE">BOOST_TEST_LE</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_LE</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">expr1</span> <span class="special">&lt;=</span>
          <span class="identifier">expr2</span></code> is not true increases the
          error count and outputs a message containing both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_gt"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_gt" title="BOOST_TEST_GT">BOOST_TEST_GT</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_GT</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">expr1</span> <span class="special">&gt;</span>
          <span class="identifier">expr2</span></code> is not true increases the
          error count and outputs a message containing both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_ge"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_ge" title="BOOST_TEST_GE">BOOST_TEST_GE</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_GE</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">expr1</span> <span class="special">&gt;=</span>
          <span class="identifier">expr2</span></code> is not true increases the
          error count and outputs a message containing both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_cstr_eq"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_cstr_eq" title="BOOST_TEST_CSTR_EQ">BOOST_TEST_CSTR_EQ</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_CSTR_EQ</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span>
</pre>
<p>
          Specialization of <code class="computeroutput"><span class="identifier">BOOST_TEST_EQ</span></code>
          which interprets <code class="computeroutput"><span class="identifier">expr1</span></code>
          and <code class="computeroutput"><span class="identifier">expr2</span></code> as pointers to
          null-terminated byte strings (C strings). If <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">strcmp</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="special">!=</span> <span class="number">0</span></code>,
          increase the error count and output a message containing both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_cstr_ne"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_cstr_ne" title="BOOST_TEST_CSTR_NE">BOOST_TEST_CSTR_NE</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_CSTR_NE</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span>
</pre>
<p>
          Specialization of <code class="computeroutput"><span class="identifier">BOOST_TEST_NE</span></code>
          which interprets <code class="computeroutput"><span class="identifier">expr1</span></code>
          and <code class="computeroutput"><span class="identifier">expr2</span></code> as pointers to
          null-terminated byte strings (C strings). If <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">strcmp</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span> <span class="special">==</span> <span class="number">0</span></code>,
          increase the error count and output a message containing both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_with"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_with" title="BOOST_TEST_WITH">BOOST_TEST_WITH</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_WITH</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">,</span> <span class="identifier">pred</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">pred</span><span class="special">(</span><span class="identifier">expr1</span><span class="special">,</span> <span class="identifier">expr2</span><span class="special">)</span></code>
          is not true increases the error count and outputs a message containing
          both expressions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_all_eq"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_all_eq" title="BOOST_TEST_ALL_EQ">BOOST_TEST_ALL_EQ</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_ALL_EQ</span><span class="special">(</span><span class="identifier">begin1</span><span class="special">,</span> <span class="identifier">end1</span><span class="special">,</span> <span class="identifier">begin2</span><span class="special">,</span> <span class="identifier">end2</span><span class="special">)</span>
</pre>
<p>
          Compares the content of two sequences. If they have different sizes, or
          if any pairwise element differs, increases the error count and outputs
          a message containing at most 8 differing elements.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_all_with"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_all_with" title="BOOST_TEST_ALL_WITH">BOOST_TEST_ALL_WITH</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_ALL_WITH</span><span class="special">(</span><span class="identifier">begin1</span><span class="special">,</span> <span class="identifier">end1</span><span class="special">,</span> <span class="identifier">begin2</span><span class="special">,</span> <span class="identifier">end2</span><span class="special">,</span> <span class="identifier">predicate</span><span class="special">)</span>
</pre>
<p>
          Compares the content of two sequences. If they have different sizes, or
          if any pairwise element do not fulfill the binary predicate, increases
          the error count and outputs a message containing at most 8 differing elements.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_throws"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_throws" title="BOOST_TEST_THROWS">BOOST_TEST_THROWS</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_THROWS</span><span class="special">(</span><span class="identifier">expr</span><span class="special">,</span> <span class="identifier">excep</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">BOOST_NO_EXCEPTIONS</span></code>
          is <span class="bold"><strong>not</strong></span> defined and if <code class="computeroutput"><span class="identifier">expr</span></code>
          does not throw an exception of type <code class="computeroutput"><span class="identifier">excep</span></code>,
          increases the error count and outputs a message containing the expression.
        </p>
<p>
          If <code class="computeroutput"><span class="identifier">BOOST_NO_EXCEPTIONS</span></code>
          is defined, this macro expands to nothing and <code class="computeroutput"><span class="identifier">expr</span></code>
          is not evaluated.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.boost_test_no_throw"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.boost_test_no_throw" title="BOOST_TEST_NO_THROW">BOOST_TEST_NO_THROW</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_NO_THROW</span><span class="special">(</span><span class="identifier">expr</span><span class="special">)</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">BOOST_NO_EXCEPTIONS</span></code>
          is <span class="bold"><strong>not</strong></span> defined and if <code class="computeroutput"><span class="identifier">expr</span></code>
          throws an exception, increases the error count and outputs a message containing
          the expression and (if possible) the exception message.
        </p>
<p>
          If <code class="computeroutput"><span class="identifier">BOOST_NO_EXCEPTIONS</span></code>
          is defined, <code class="computeroutput"><span class="identifier">expr</span></code> is evaluated.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.report_errors"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.report_errors" title="report_errors">report_errors</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">report_errors</span><span class="special">()</span>
</pre>
<p>
          Return the error count from <code class="computeroutput"><span class="identifier">main</span></code>.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_te.example"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_te.example" title="Example">Example</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">lightweight_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">int</span> <span class="identifier">sqr</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">x</span> <span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">*</span> <span class="identifier">x</span><span class="special">;</span>
<span class="special">}</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="identifier">sqr</span><span class="special">(</span><span class="number">2</span><span class="special">)</span> <span class="special">==</span> <span class="number">4</span> <span class="special">);</span>
    <span class="identifier">BOOST_TEST_EQ</span><span class="special">(</span> <span class="identifier">sqr</span><span class="special">(-</span><span class="number">3</span><span class="special">),</span> <span class="number">9</span> <span class="special">);</span>

    <span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">report_errors</span><span class="special">();</span>
<span class="special">}</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_t0"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_t0" title="Header &lt;boost/core/lightweight_test_trait.hpp&gt;">Header
      &lt;boost/core/lightweight_test_trait.hpp&gt;</a>
</h3></div></div></div>
<p>
        The header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">lightweight_test_trait</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        defines a couple of extra macros for testing compile-time traits that return
        a boolean value.
      </p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_t0.synopsis"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_t0.synopsis" title="Synopsis">Synopsis</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_TRAIT_TRUE</span><span class="special">((</span><span class="identifier">Trait</span><span class="special">))</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_TRAIT_FALSE</span><span class="special">((</span><span class="identifier">Trait</span><span class="special">))</span> <span class="comment">/*unspecified*/</span>
<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_TRAIT_SAME</span><span class="special">(</span><span class="identifier">Type1</span><span class="special">,</span> <span class="identifier">Type2</span><span class="special">)</span> <span class="comment">/*unspecified*/</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_t0.boost_test_trait_true"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_t0.boost_test_trait_true" title="BOOST_TEST_TRAIT_TRUE">BOOST_TEST_TRAIT_TRUE</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_TRAIT_TRUE</span><span class="special">((</span><span class="identifier">Trait</span><span class="special">))</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">Trait</span><span class="special">::</span><span class="identifier">value</span> <span class="special">!=</span> <span class="keyword">true</span></code> increases the error count and outputs
          a message containing <code class="computeroutput"><span class="identifier">Trait</span></code>.
          Note the double set of parentheses; these enable <code class="computeroutput"><span class="identifier">Trait</span></code>
          to contain a comma, which is common for templates.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_t0.boost_test_trait_false"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_t0.boost_test_trait_false" title="BOOST_TEST_TRAIT_FALSE">BOOST_TEST_TRAIT_FALSE</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_TRAIT_FALSE</span><span class="special">((</span><span class="identifier">Trait</span><span class="special">))</span>
</pre>
<p>
          If <code class="computeroutput"><span class="identifier">Trait</span><span class="special">::</span><span class="identifier">value</span> <span class="special">!=</span> <span class="keyword">false</span></code> increases the error count and outputs
          a message containing <code class="computeroutput"><span class="identifier">Trait</span></code>.
          Note the double set of parentheses.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_t0.boost_test_trait_same"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_t0.boost_test_trait_same" title="BOOST_TEST_TRAIT_SAME">BOOST_TEST_TRAIT_SAME</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">BOOST_TEST_TRAIT_SAME</span><span class="special">(</span><span class="identifier">Type1</span><span class="special">,</span> <span class="identifier">Type2</span><span class="special">)</span>
</pre>
<p>
          If the two types are not the same, increases the error count and outputs
          a message containing them. This macro requires that the compiler supports
          variadic macros and <code class="computeroutput"><span class="identifier">__VA_ARGS__</span></code>.
          (Note that unlike <code class="computeroutput"><span class="identifier">BOOST_TEST_TRAIT_TRUE</span></code>
          and <code class="computeroutput"><span class="identifier">BOOST_TEST_TRAIT_FALSE</span></code>,
          this macro only requires a single set of parentheses.)
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.lightweight_test.header_boost_core_lightweight_t0.example"></a><a class="link" href="lightweight_test.html#core.lightweight_test.header_boost_core_lightweight_t0.example" title="Example">Example</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">lightweight_test_trait</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">is_same</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">type</span><span class="special">;</span>
<span class="special">};</span>

<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">;</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="identifier">BOOST_TEST_TRAIT_TRUE</span><span class="special">((</span> <span class="identifier">is_same</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">long</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">,</span> <span class="keyword">int</span><span class="special">&gt;</span> <span class="special">));</span>

    <span class="identifier">BOOST_TEST_TRAIT_SAME</span><span class="special">(</span> <span class="identifier">X</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">long</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">,</span> <span class="keyword">int</span> <span class="special">);</span>

    <span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">report_errors</span><span class="special">();</span>
<span class="special">}</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="is_same.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="no_exceptions_support.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
